package ar.com.tallerdos.smartdinner.gson.serializer;

import java.lang.reflect.Type;

import ar.com.tallerdos.smartdinner.model.Mesa;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

public class MesaCustomSerializer implements JsonDeserializer<Mesa> {

    @Override
    public Mesa deserialize(JsonElement json, Type arg1,
	    JsonDeserializationContext arg2) throws JsonParseException {
	JsonObject jo = (JsonObject) json;
	
	Mesa mesa = new Mesa(jo.get("id").getAsInt(), 0, jo.get("codigo").getAsInt());
	mesa.setEstado(jo.get("estado").getAsInt());
	mesa.setPosX(jo.get("pos_x").getAsInt());
	mesa.setPosY(jo.get("pos_x").getAsInt());
	mesa.setActivo(jo.get("activo").getAsBoolean());
	
	return mesa;
    }

}
